home *** CD-ROM | disk | FTP | other *** search
- property ancestor, bluesCAR, carYpos, carXpos, CAR, carIsDrivingHori, carIsDrivingVert, myDirection, myCounter, myRatio, animCounter, historyList, goingInReverse
- global myGridArray, gCarObj, gGamesMasterObj, jailBubList, BLOCKWIDTH, BLOCKHEIGHT, POLICESPRITES
-
- on new me
- set ancestor to new(script "carScript")
- return me
- end
-
- on init me, xPos, yPos, ratioNum
- set carXpos to xPos
- set carYpos to yPos
- set CAR to findSpace(me)
- set carIsDrivingHori to 0
- set carIsDrivingVert to 0
- set myDirection to 0
- set myCounter to 0
- set animCounter to 0
- set goingInReverse to 0
- set historyList to []
- set myRatio to ratioNum
- set bluesCAR to the CAR of gCarObj
- appear(me, "po1N.PCT")
- end
-
- on findSpace me
- repeat with x = POLICESPRITES to POLICESPRITES + 4
- if the memberNum of sprite x = 0 then
- return x
- exit repeat
- end if
- end repeat
- return 0
- end
-
- on mainRoutine me
- animateCar(me)
- if carIsDrivingHori then
- set myCounter to myCounter + 1
- if myCounter > (BLOCKWIDTH / myRatio) then
- set the carIsDrivingHori of me to 0
- else
- set the locH of sprite CAR to the locH of sprite CAR + (myDirection * myRatio)
- end if
- else
- if the carIsDrivingVert of me then
- set myCounter to myCounter + 1
- if myCounter > (BLOCKHEIGHT / myRatio) then
- set the carIsDrivingVert of me to 0
- else
- set the locV of sprite CAR to the locV of sprite CAR + (myDirection * myRatio)
- end if
- else
- if not goingInReverse then
- findBlues(me)
- else
- set myRatio to 20
- returnToBase(me)
- end if
- end if
- end if
- end
-
- on animateCar me
- set animCounter to animCounter + 1
- if animCounter > 3 then
- set animCounter to 1
- end if
- changeCar(me, "po" & animCounter)
- end
-
- on findBlues me
- set blueH to the locH of sprite bluesCAR
- set blueV to the locV of sprite bluesCAR
- set carH to the locH of sprite CAR
- set carV to the locV of sprite CAR
- if (blueV < carV) and (blueH < carH) then
- pickRoute(me, [4, 1])
- else
- if (blueV < carV) and (blueH > carH) then
- pickRoute(me, [1, 2])
- else
- if (blueV > carV) and (blueH > carH) then
- pickRoute(me, [2, 3])
- else
- if (blueV > carV) and (blueH < carH) then
- pickRoute(me, [3, 4])
- else
- if blueV < carV then
- goRoute(me, 1)
- else
- if blueH > carH then
- goRoute(me, 2)
- else
- if blueV > carV then
- goRoute(me, 3)
- else
- if blueH < carH then
- goRoute(me, 4)
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end if
- end
-
- on returnToBase me
- if historyList <> [] then
- set nextDirection to getAt(historyList, count(historyList))
- deleteAt(historyList, count(historyList))
- case nextDirection of
- 1:
- set the member of sprite CAR to member ("po" & animCounter & "N.PCT")
- moveVertical(me, -1)
- 2:
- set the member of sprite CAR to member ("po" & animCounter & "E.PCT")
- moveHorizontal(me, 1)
- 3:
- set the member of sprite CAR to member ("po" & animCounter & "S.PCT")
- moveVertical(me, 1)
- 4:
- set the member of sprite CAR to member ("po" & animCounter & "W.PCT")
- moveHorizontal(me, -1)
- end case
- else
- set the policeCounter of gGamesMasterObj to the policeCounter of gGamesMasterObj - 1
- destroy(me)
- end if
- end
-
- on pickRoute me, dirList
- set oldList to value(string(dirList))
- set firstDir to getAt(dirList, random(count(dirList)))
- deleteAt(dirList, getOne(dirList, firstDir))
- set secondDir to getAt(dirList, 1)
- if carCanGoThatWay(me, firstDir) then
- whichWay(me, firstDir)
- else
- if carCanGoThatWay(me, secondDir) then
- whichWay(me, secondDir)
- else
- alternativeRoute(me, oldList)
- end if
- end if
- end
-
- on goRoute me, dir
- if carCanGoThatWay(me, dir) then
- whichWay(me, dir)
- else
- alternativeRoute(me, dir)
- end if
- end
-
- on alternativeRoute me, unknownType
- set bigList to [1, 2, 3, 4]
- if listp(unknownType) then
- repeat with i = 1 to count(unknownType)
- set tempInt to getAt(unknownType, i)
- deleteAt(bigList, getOne(bigList, tempInt))
- end repeat
- else
- deleteAt(bigList, getOne(bigList, unknownType))
- end if
- goRoute(me, getAt(bigList, random(count(bigList))))
- end
-
- on carCanGoThatWay me, indexNum
- set myOptions to getIndex(me, myGridArray, carYpos, carXpos)
- if getAt(myOptions, indexNum) = 1 then
- return 1
- end if
- return 0
- end
-
- on whichWay me, indexNum
- case indexNum of
- 1:
- set carYpos to carYpos - 1
- if nextSpaceFree(me) then
- set the member of sprite CAR to member ("po" & animCounter & "N.PCT")
- moveVertical(me, -1)
- append(historyList, 3)
- else
- set carYpos to carYpos + 1
- end if
- 2:
- set carXpos to carXpos + 1
- if nextSpaceFree(me) then
- set the member of sprite CAR to member ("po" & animCounter & "E.PCT")
- moveHorizontal(me, 1)
- append(historyList, 4)
- else
- set carXpos to carXpos - 1
- end if
- 3:
- set carYpos to carYpos + 1
- if nextSpaceFree(me) then
- set the member of sprite CAR to member ("po" & animCounter & "S.PCT")
- moveVertical(me, 1)
- append(historyList, 1)
- else
- set carYpos to carYpos - 1
- end if
- 4:
- set carXpos to carXpos - 1
- if nextSpaceFree(me) then
- set the member of sprite CAR to member ("po" & animCounter & "W.PCT")
- moveHorizontal(me, -1)
- append(historyList, 2)
- else
- set carXpos to carXpos + 1
- end if
- end case
- end
-
- on nextSpaceFree me
- repeat with i = 2 to count(the actorList)
- set myObject to getAt(the actorList, i)
- if the CAR of myObject <> CAR then
- if (the carXpos of myObject = carXpos) and (the carYpos of myObject = carYpos) then
- if the CAR of myObject = the CAR of gCarObj then
- set whichMember to getAt(["dead", "last", "first"], the bluesWarnings of gGamesMasterObj)
- createBubble(me, "bubbleScript", jailBubList, whichMember)
- setCaught(gGamesMasterObj)
- end if
- return 0
- exit repeat
- end if
- end if
- end repeat
- return 1
- end
-
- on createBubble me, whichScript, whichList, whichMember
- if whichList = [] then
- set horPos to the locH of sprite the CAR of me
- set verPos to the locV of sprite the CAR of me
- if horPos < 280 then
- set xPos to horPos + 15
- set hCode to 4
- else
- set xPos to horPos - 15
- set hCode to 2
- end if
- if verPos < 180 then
- set yPos to verPos + 15
- set vCode to 1
- else
- set yPos to verPos - 15
- set vCode to 3
- end if
- set bubbleObj to new(script whichScript)
- appear(bubbleObj, xPos, yPos, whichMember & vCode & hCode & ".PCT", whichList)
- end if
- end
-